//
//  FWPageButton.m
//  BirdLoveSheep
//
//  Created by wwj on 16/3/17.
//  Copyright © 2016年 wwj. All rights reserved.
//

#import "FWPageButton.h"

@interface FWPageButton ()
@property (weak, nonatomic) UIButton *seelectBtn;
@end

@implementation FWPageButton

- (instancetype)initWithCoder:(NSCoder *)coder{
    self = [super initWithCoder:coder];
    if (self) {
        [self initView];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self initView];
    }
    return self;
}

- (void)initView{
    
    [self setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [self setTitleColor:[UIColor orangeColor] forState:UIControlStateSelected];
    self.titleLabel.font = [UIFont systemFontOfSize:14];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    [self addTarget:self action:@selector(onClickBtn:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)setTitle:(NSString *)title{
    _title = title;
    [self setTitle:title forState:UIControlStateNormal];
}

- (void)setScal:(CGFloat)scal{
    _scal = scal;
    CGFloat btnScal = 1 + _scal * 0.08;
    self.transform = CGAffineTransformMakeScale(btnScal, btnScal);
    
}

- (void)onClickBtn:(UIButton *)btn{
    _seelectBtn.selected = NO;
    btn.selected = YES;
    _seelectBtn = btn;
    NSInteger index = [self.superview.subviews indexOfObject:btn];
    if ([_delegate respondsToSelector:@selector(onClickPageButton:index:)]) {
        [_delegate onClickPageButton:self index:index];
    }
}

@end
